package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;	

import com.mysql.jdbc.Statement;
	
public class ModificarReserva  extends HttpServlet{


		protected void doPost(HttpServletRequest req, HttpServletResponse resp)
				throws ServletException, IOException {
			
		
			
			
			String nuevovuelo = req.getParameter("vueloasignado");//que vuelo es
			String nuevopqt = req.getParameter("paquetelist");						
			String idReserva =req.getParameter("idReservaC");
			java.sql.Connection con;

			String databaseName = "grupo_1_db";
		  try {
			Class.forName("com.mysql.jdbc.Driver"); 
			
			con = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + databaseName,"root","ignacio"); 
			Statement st1= (Statement) con.createStatement(); 		
			Statement st2= (Statement) con.createStatement(); 	
			Statement st3= (Statement) con.createStatement(); 	
		
					 
		String querydescontarAsientos = "update reservas set idpaquete = "+nuevopqt+", idvuelo = " +nuevovuelo + " where idreservas = " + idReserva;
	     st2.executeUpdate(querydescontarAsientos);	
		
		 req.getRequestDispatcher("/ModificarPaso3.jsp").forward(req, resp);
		
			
			  if(con!=null) {con.close();}
			
		  }
			catch (Exception e)
			{
				response(req,resp, "Error en la conexion con la base de datos al modificar la reserva");
			}
		  
		  
		 
	
		  
			
			//vueloasignado id
		
			//response(resp, msjdevolver);
			
			//if ("edu4java".equals(user) && "eli4java".equals(pass)) {
			//	response(resp, "login ok");
			//} else {
			//	response(resp, "invalid login");
			//}
		}

		private void response(HttpServletRequest req,HttpServletResponse resp, String msg)
				throws IOException, ServletException {
			PrintWriter out = resp.getWriter();
			out.println("<html>");
			out.println("<body>");
			
			//out.println("<script>alert(1);</script>");
			out.println("<t1>" + msg + "</t1>");
			out.println("</body>");
			out.println("</html>");
			
			  // String message = "Hello World";
			 //  req.setAttribute("message", msg); // This will be available as ${message}
		      //  req.getRequestDispatcher("/ValidarReserva.jsp").forward(req, resp);
		 

			
		}
		

}
